package com.sky.controller.admin;

import com.sky.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/*
    TODO swagger文档编写
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置营业状态
     * 使用redis存储
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result status(@PathVariable("status") String status){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("shop_status", status);
        return Result.success();
    }


    /**
     * 管理端查询营业状态
     * @return
     */
    @GetMapping("/status")
    public Result getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        return Result.success(Integer.parseInt((String) valueOperations.get("shop_status")));
    }
}
